﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.ServiceModel;
using System.Text;
using LinFu.IoC;
using LinFu.IoC.Configuration.Interfaces;
using LinFu.IoC.Interfaces;
using LinFu.IoC.Configuration;
using LinFu.Reflection;
using Mono.Cecil;

namespace CoreEx.Wcf.Server.Implementation
{
    /// <summary>
    /// Injects an operation method repository into an <see cref="IServiceContainer"/> instance.
    /// </summary>
    /// <remarks>
    /// The repository is used to determine the methods that should have the <see cref="OperationContractAttribute"/> injected.
    /// <seealso cref="ProxyMethodBuilderInterceptor"/>
    /// <seealso cref="ProxyFactoryInterceptor"/>
    /// <see cref="OperationContractPostProcessor"/>
    /// </remarks>
    [LoaderPlugin]
    public class OperationContractPlugin : IContainerPlugin
    {
        public void BeginLoad(IServiceContainer target){}
        
        public void EndLoad(IServiceContainer target)
        {
            target.Inject<IDictionary<Type, IList<MethodInfo>>>().Using(() => new Dictionary<Type, IList<MethodInfo>>()).AsSingleton();
            target.Inject<IDictionary<string,Assembly>>().Using(() => new Dictionary<string, Assembly>()).AsSingleton();
        }
    }
}